
function checkMobileCart(is_mobile) {
    if (is_mobile != 0) {
        $('#foodBasket').css({"bottom": "300px"})
    }
}

function showbgbox(div, top, left) {
    var windowWidth = $(window).width();
    var windowHeight = $(window).height();
    var width = $(div).outerWidth() ? $(div).outerWidth() : $(div).children("div").outerHeight();
    var height = $(div).outerHeight() ? $(div).outerHeight() : $(div).children("div").outerHeight();

    var scroolHeight = $(document).scrollTop();

    if (top == -1) {
        top = scroolHeight;
    } else {

        top = (windowHeight - height) / 2 + scroolHeight;
    }

    $(div).css({
        "position": "absolute",
        "top": top,
        "left": (windowWidth - width) / 2,
        "z-index": 9992
    });

    $('#filter').addClass('filter');
    var h = $('body').height();
    if (h < windowHeight) {
        h = windowHeight;
    }
    $('#filter').css({
        "height": h
    })

    $(div).show();
    $('#filter').animate({
        "opacity": 0.7
    }, 200)

    drag(".browsebox", ".browsebox .head");
}
function drag(body, head) {
    $(body).anyDrag({
        obj: head,
        maxTop: true,
        alpha: 0.8
    });
    /**
     /* 【参数说明】
     /* obj 拖动热区，拖动所选对象的什么位置 可拖动，默认为 对象整体可拖动。 如果只要标题栏可拖动 请传入 选择器(class 或是 id)
     /* maxTop 拖动放开后 是否在最顶层，默认为false  不在最顶层。
     /* alpha 拖动时 被拖动对象的透明度，默认为1. 不透明。
     **/
}
function showbgbox3(div) {

    var windowWidth = $(window).width();
    var windowHeight = $(window).height();
    var width = $(div).children("div").outerWidth() ? $(div).children("div").outerWidth() : $(div).outerWidth();

    var scroolHeight = $(document).scrollTop();
    var height = $(div).outerHeight();
    $(div).css({
        "position": "absolute",
        "top": (windowHeight - height) / 2 - 50 + scroolHeight,
        "left": (windowWidth - width) / 2,
        "z-index": 9999
    });
    $('#filter2').addClass('filter');
    var h = $('body').height();
    if (h < windowHeight) {
        h = windowHeight;
    }
    $('#filter2').css({
        "height": h,
        "z-index": 9993
    })

    $(div).show();
    $('#filter2').animate({
        "opacity": 0.7
    }, 200);
    drag(".browsebox", "#headbox");

}
function closebgbox3(div, focus, url) {

    if (focus == undefined || focus == 'undefined') {
        focus = '';
    }
    if (url == undefined || url == 'undefined') {
        url = '';
    }

    if (url == -1) {
        location.reload();
    } else if (url.length > 2) {
        document.location.href = url;
    } else {
        $('#filter2').removeClass('filter').css({
            "height": 0
        });
        $(div).empty();
        $('#filter2').animate({
            "opacity": 0.1
        }, 300)
    }
    if (focus) {
        $(focus).focus();
    }
}
function closebgbox(div) {
    $('#filter').removeClass('filter').css({
        "height": 0
    });
    $(div).empty();
    $('#filter').animate({
        "opacity": 0.1
    }, 300)
    $('#checkuser').val('');
    $('#mainbox').css({"left": 0, "top": 0})
}

function showTip(title, content, mtype, t, focus, location) {
    var cla = 'wrongIcon';
    if (mtype == '1') {
        cla = 'rightIcon';
    } else if (mtype == '2') {
        cla = 'confirmIcon';
    }
    var div = "<div class='browsebox'><div class='head' id='headbox'>\n\
        <a class='close' onclick=closebgbox3('#mainbox2','" + focus + "','" + location + "')></a>" + title + "\n\
    </div><div class='boxcontent'><span class='" + cla + "'></span><span class='innerBoxContent'>" + content + "</span>\n\
<div class='clear'></div></div><div class='footbox'><input class='footBoxBtn' type='button' onclick=closebgbox3('#mainbox2','" + focus + "','" + location + "') value='确 定'/></div></div>";
    $('#mainbox2').html(div);

    showbgbox3('#mainbox2');
    if (t > 0) {
        setTimeout(function() {
            closebgbox3('#mainbox2', focus, location);
        }, t * 1000);
    }
}
function confirmBox(obj, title, func) {
    var url = $('#SITE_URL').val();
    if (!func) {
        func = obj.attr("data-func");
    }
    var div = "<div class='browsebox' style='width:405px;'>\n\
    <div class='head' id='headbox'>\n\
        <a class='close' onclick=closebgbox3('#mainbox2')></a><span id='title'>信息确认</span>\n\
    </div>\n\
    <div class='content'>\n\
        <div style='margin:25px auto;width:330px'>\n\
        <span  style='margin:5px 20px;float:left;' class='alarmIcon'></span>\n\
        <div style='font-size:16px;font-weight:bold;float:left;margin:20px 0 0 0;width:210px;text-align:left'>" + title + "</div>\n\
        <div class='clear'></div>\n\
        </div>\n\
        <div style=' padding: 8px 20px; text-align: center;'>\n\
            <input type='button' value='确 定' onclick=" + func + " class='confirmBtn'>\n\
            <input  type='button'  value='取 消' onclick=closebgbox3('#mainbox2') class='cancelBtn'>\n\
        </div>\n\
    </div>\n\
</div>";

    $('#mainbox2').html(div);
    showbgbox3('#mainbox2', 0, 0);
}
function cancelOrder(id) {
    $.post(getUrl("Ajax/cancelOrder"), {
        id: id
    }, function(data) {
        showTip('系统提示', "取消订单成功！", '2', '', '', '-1');
    })
}
function comment(id) {
    var url = $("#comment_btn").attr("data-url");
    $.post(url, {
        id: id
    }, function(data) {
        $('#mainbox').html(data);
        showbgbox('#browsebox', 0, 0);
        $("#shop_name").html($("#sname_" + id).html());
    })
}
function showQuestionsBox() {
    var div = "<div class='browsebox' id='browsebox' style='width:456px;'>\n\
    <div class='head' id='headbox'>\n\
        <a class='close' onclick=closebgbox('#mainbox')></a>\n\
        <span id='title'>问题反馈</span></div>\n\
<div class='boxcontent' style='padding:0'>\n\
<div class='clear_cart_inner'>\n\
<div class='cf_con'>\n\
<div id=feedbackTip><label style='text-align:left'> 小提示：催单请进入相应餐厅的页面进行留言，这样餐厅就能看见哦~</label>\n\
<textarea id=feedBackTipContent style='width:98% '></textarea></div>\n\
<p  style='margin:8px 0;tetx-align:left'> 我们的回复将发到个人中心的问题反馈里，感谢您的建议。</p>\n\
<div class='do_clear_cart clearfix' style='padding:16px 0 0 0;background:none'>\n\
<a class='do_not_clear' onclick=addQuestions()>确认</a><a class='do_clear'  onclick=closebgbox('#mainbox')>取消</a>\n\
</div></div></div></div>";
    $('#mainbox').html(div);
    showbgbox('#browsebox', 0, 0);
}
function recommendShops() {
    $.post(getUrl("Box/recommendShops"), {
    }, function(data) {
        $('#mainbox').html(data);
        showbgbox('#browsebox', 0, 0);
    })
}
function addQuestions() {
    var content = $("#feedBackTipContent").val();
    if (content == '') {
        showTip('系统提示', "内容不能为空！", '2', 1.5, '#feedBackTipContent');
        return false;
    }

    $.post(getUrl("Ajax/addQuestions"), {
        content: content
    }, function(data) {
        closebgbox('#mainbox');
        showTip('系统提示', "感谢您的宝贵建议！", '2', 1.5);
    })
}
function addToCollect(id,mtype){
    $.post(getUrl("Ajax/addToCollect"), {
        id: id,
        mtype:mtype
    }, function(data) {
        closebgbox('#mainbox');
        showTip('系统提示', "感谢您的宝贵建议！", '2', 1.5);
    })
}